<template>
  <div>
    <div class="app-container">
      <div class="addon-form cl">
        <el-form :inline="true" :model="searchData" class="z">
          <el-form-item label="应用名称">
            <el-input v-model="searchData['name like']" clearable placeholder="应用名称" />
          </el-form-item>
          <el-form-item>
            <el-button type="primary" @click="onSearch">查询</el-button>
          </el-form-item>
        </el-form>
        <div class="work-button y">
          <el-button type="primary" @click="createForm(0)">新增</el-button>
        </div>
      </div>
      <el-table :data="dkTableData" style="width: 100%" class="table">
        <el-table-column prop="id" label="id" width="80" align="center" sortable="custom" />
        <el-table-column prop="logo" label="应用图标" min-width="100" align="center">
          <template #default="scope">
            <el-image :src="scope.row.logo" shape="square" style="width: 80px; height: 80px" />
          </template>
        </el-table-column>
        <el-table-column prop="name" label="应用名" align="center" />
        <el-table-column prop="create_time" label="日期" width="260">
          <template #default="scope">
            <div>
              <div>
                <p class="d-text-grey u-m-b-5">创建日期：</p>
                <p>{{ scope.row.create_time }}</p>
              </div>
              <div>
                <p class="d-text-grey u-m-b-5">更新日期：</p>
                <p>{{ scope.row.update_time }}</p>
              </div>
            </div>
          </template>
        </el-table-column>
        <el-table-column label="操作" width="80">
          <template #default="scope">
            <el-button size="small" type="primary" @click="createForm(scope.row.id)">编辑</el-button>
          </template>
        </el-table-column>
      </el-table>
      <div class="app-container u-m-10 u-p-10">
        <el-pagination
          background
          layout="total,prev, pager, next"
          :total="total"
          :current-page="page"
          :page-size="pageSize"
          @current-change="currentChange"
        />
      </div>
    </div>
    <dk-form-create-dialog ref="fc" width="1000px" :form-data="formData" top="10vh" @submit="onSubmit()" />
  </div>
</template>

<script>
import clipboard from '@/utils/clipboard'
import { getMinAppOpenForm, getMinAppOpenList } from '@/api/platform/app/app_open'

export default {
  name: 'MinAppOpenList',
  props: {
    type: {
      default: 'dy',
      type: String
    }
  },
  data() {
    return {
      page: 1,
      pageSize: 10,
      total: 0,
      dkTableData: [],
      searchData: {
        type: this.type
      },
      order: '',
      dialogFormVisible: false,
      formData: null
    }
  },

  mounted() {
    this.getList(this.page)
  },
  methods: {
    handleClipboard(text, event) {
      clipboard(text, event)
    },
    onSearch() {
      this.getList()
    },
    currentChange(page) {
      this.getList(page)
    },
    onSubmit() {
      this.getList(0)
    },
    getList(page) {
      this.page = page
      getMinAppOpenList(this.page, this.pageSize, this.searchData, this.type).then((res) => {
        this.dkTableData = res.data
        this.total = parseInt(res.msg)
      })
    },
    createForm(id) {
      getMinAppOpenForm(id, this.type).then((res) => {
        this.formData = res.data
        this.$refs.fc.dialogFormVisible = true
      })
    }
  }
}
</script>
<style scoped lang="scss">
.search_user {
  margin-top: 10px;
  background: #f5f7fa;
  padding: 10px;
}
</style>
